<template>
  <div class="hello">
    <el-form ref="tableForm" :model="form" :rules="rules" :show-message="false">
      <el-table :data="form.editTableData">
        <el-table-column type="index" width="60" label="序号"></el-table-column>
        <el-table-column prop="value1" min-width="100" label="产品名称">
          <template slot="header">
            <span>
              <span style="color: #f56c6c">*</span>
              产品名称
            </span>
          </template>
          <template slot-scope="scope">
            <el-form-item :prop="'editTableData.' + scope.$index + '.value1'" :rules="rules.value1">
              <el-input v-model="scope.row.value1" size="mini" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="value2" min-width="100" label="产品名称2">
          <template slot-scope="scope">
            <el-form-item :prop="'editTableData.' + scope.$index + '.value2'" :rules="rules.value2">
              <el-select v-model="scope.row.value2" size="mini">
                <el-option
                  v-for="item in options1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="deleteHandle(scope.$index)">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <el-button @click="addTable">addTable</el-button>
      <el-button @click="submit">提交</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      form: {
        editTableData: [
          {
            value1: "",
            value2: "",
          },
        ],
      },
      showTableData: [],
      options1: [
        { label: "1", value: "1" },
        { label: "2", value: "2" },
      ],
      rules: {
        value1: [{ required: true, message: "请输入123", trigger: "blur" }],
        value2: [{ required: true, message: "请输入123", trigger: "blur" }],
      },
    }
  },
  methods: {
    addTable() {
      this.form.editTableData.push({
        value1: "",
        value2: "",
      })
    },
    submit() {
      console.log(this.form.editTableData)
      this.$refs.tableForm.validate(valid => {
        if (valid) {
          alert("submit!")
        } else {
          console.log("error submit!!")
          return false
        }
      })
    },
    deleteHandle(i) {
      this.form.editTableData.splice(i, 1)
    },
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
.hello {
  .el-form-item {
    margin-bottom: 0;
    height: 32px;
    line-height: 32px;
  }
  .el-form-item__content {
    line-height: 32px;
  }
}
</style>
